# This is a program that renders Julia set image along with a text as a PPM
# image. NOTE: when rendering this in "higher" resolutions, such as 128x100,
# the current C interpreter takes a while to finish, keep in mind this isn't
# too optimized and the interpreter is slow.

~8
~IMG_mem:60000
~0

IMG_out: -> .

~"../programs/imglib.cmn"
~"../programs/minilib.cmn"

IMAGE_W: 128 .
IMAGE_H: 90 .

VIEW_W: 3000 .
VIEW_H: 2000 .

JULIA_X: -368 .
JULIA_Y: -634 .

# in: x, y, 4x4bitmap
drawChar:
  4
  @'
    4
    @'
      $2 2 % ?
        $0 $5 + -- $2 $5 + -- IMG_BLACK IMG_setPixel
      .

      $2 2 / $:3  # shift mask by one to the right
      --
    .
    ^

    --
  .
  ^
  ^ ^ ^
.

# julia set, modified function from the Mandelbrot example
julia:
       # x
       # y
  0    # iteration
  $2   # cx
  $2   # cy

  @@
    $2 63 <' ?
      ^ ++ $:3
    ;
      ^ ^ !@
    .

    $1 $0 * $1 $0 * - 1024 // JULIA_X +
    $2 $2 * 512 // JULIA_Y + $:2
    $:2
    
    $1 $0 * $1 $0 * + 4194304 > ?
      !@
    .
  .

  ^ ^ $:2 ^
.

IMAGE_W IMAGE_H IMG_new

IMAGE_H
@'
  --

  IMAGE_W
  @'
    --

    $0 $2

    $1 VIEW_W * IMAGE_W / VIEW_W 2 / -
    $1 VIEW_H * IMAGE_H / VIEW_H 2 / -

    julia 4 * $0 2 * cos8 255 $1 -     # create RGB color
 
    IMG_setPixel
  .
  ^
.
^

1  1  +b1101111110011001 drawChar # M
6  1  +b0110100111111001 drawChar # A
11 1  +b1110100110011110 drawChar # D
16 1  +b1111111010001111 drawChar # E

25 1  +b1001100111111101 drawChar # W
30 1  +b0100010001000100 drawChar # I
33 1  +b1110010001000100 drawChar # T
37 1  +b1001111110011001 drawChar # H

45 1  +b0111100010000111 drawChar # C
50 1  +b0110100110010110 drawChar # O
55 1  +b1101111110011001 drawChar # M
60 1  +b1001100110010110 drawChar # U
65 1  +b1001110110111001 drawChar # N

IMG_toPPM
